﻿using gt.framework.Log;
using gt.webapi.core.Entity.Client;
using gt.webapi.core.Entity.Options;
using System.Collections.Generic;
using System.Web.Http;

namespace gt.webapi.core.sample2
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API 配置和服务

            // Web API 路由
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            var clients = new List<AuthorityEntity> { new AuthorityEntity() { Name = "test_client", Appkey = "test", Appsecret = "123456", HasAllControllerActions = true } };

            WebApiCoreOption coreConfig = new WebApiCoreOption
            {
                Authority = new AuthorityOption(clients).UsingBasicAuthentication(),
                Log = new LogOption(new FileLogWrapper("InfoLog"), new FileLogWrapper("ErrorLog")),
                IpLimit = new IpLimitOption(new List<string> { "127.0.0.1" })
            };

            config.RegisterWebApiCore(coreConfig);
        }
    }
}
